package com.myaxuan.controller.websocket;

import com.myaxuan.common.Constant;
import com.myaxuan.entity.chat.WiselyMessage;
import com.myaxuan.entity.chat.WiselyResponse;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;


/**
 * Created by pc255 on 2018/3/5.
 */
@Controller
public class WsController {

	@RequestMapping("chat")
	public String index(){
		return "chat";
	}

	@MessageMapping(Constant.FORETOSERVERPATH)//@MessageMapping和@RequestMapping功能类似，用于设置URL映射地址，浏览器向服务器发起请求，需要通过该地址。
	@SendTo(Constant.PRODUCERPATH)//如果服务器接受到了消息，就会对订阅了@SendTo括号中的地址传送消息。
	public WiselyResponse say(WiselyMessage message) throws Exception {
		return new WiselyResponse("Welcome, " + message.getName() + "!");
	}
}
